package controllers;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import com.ning.http.client.Cookie;

import play.mvc.Controller;
import java.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;



public class inserirClasse extends Application {

	private static Connection conexao;
	private static Statement comando;
	
	
	
	/***********************************************************************************/
	
	protected static void conectar() throws SQLException {  
	    
		  
		try {
			Class.forName("org.postgresql.Driver");
		} catch (ClassNotFoundException e) {
		}

			conexao = DriverManager.getConnection(  
			        "jdbc:postgresql://localhost:5432/SGRv2",  
			        "postgres",  
			        "senha");
		
			comando =  conexao.createStatement();

	}

    /***********************************************************************************/
	
	public static void inserirClasse(String valor) {
		
		render(valor);
	}

	/***********************************************************************************/
	
	public static void inserir( String nome, String caracteristica) throws SQLException
	{
		
		String valor = "nome";	
		
		
		if(nome == "" || nome == null)
		{
			valor = "O campo 'nome da classe' não pode ser vazio.";
			//inserirClasse("O campo 'nome da classe' não pode ser vazio.");

		}
		else
		{
			valor = "Inserção realizada com sucesso";
			conectar();
			
			comando.executeUpdate("insert into classe (" +
			"nome, " +
	        "caracteristica "+
	       
	        ") values (" +
	        
	        "'" + nome + "', " +
	        "'" + caracteristica + "' " +
	       
			")");
			visualizarClasses.visualizarClasses();
		}
	}
	
	/*************************************************************/


}
